package com.devunion.reader.server.mediator;

import com.devunion.bogdan.model.project.Paper;
import com.devunion.bogdan.model.project.Project;
import com.devunion.reader.client.to.PaperTo;
import com.devunion.reader.client.to.ProjectTo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Timoshenko Alexander 28.05.2009 : 10:02:49
 */
public class ProjectMediator implements IMediator<Project, ProjectTo> {
    private PaperMediator paperMediator;

    public void setPaperMediator(PaperMediator paperMediator) {
        this.paperMediator = paperMediator;
    }

    public ProjectTo copyFromEntity(Project anEntity) {
        ProjectTo theTo = new ProjectTo();
        theTo.setId(anEntity.getProjectId());
        theTo.setProjectName(anEntity.getName());

        List<PaperTo> thePaperToList = new ArrayList<PaperTo>();
        if (anEntity.getEntries() != null) {
            for (Paper anEach : anEntity.getEntries()) {
                thePaperToList.add(paperMediator.copyFromEntity(anEach));
            }
        }
        theTo.setEntries(thePaperToList);
        return theTo;
    }
}
